import time

class Msg(object):
    def __init__(self):
        pass
    def send(self):
        return "success"
class TextMsg(Msg):
    def __init__(self, toUserName, fromUserName, content):
        self.__dict = dict()
        self.__dict['ToUserName'] = toUserName
        self.__dict['FromUserName'] = fromUserName
        self.__dict['CreateTime'] = int(time.time())
        self.__dict['Content'] = content
    def send(self):
        XmlForm = """
        <xml>
        <ToUserName><![CDATA[{ToUserName}]]></ToUserName>
        <FromUserName><![CDATA[{FromUserName}]]></FromUserName>
        <CreateTime>{CreateTime}</CreateTime>
        <MsgType><![CDATA[text]]></MsgType>
        <Content><![CDATA[{Content}]]></Content>
        </xml>
        """
        return XmlForm.format(**self.__dict)
class ImageMsg(Msg):
	def __init__(self, toUserName, fromUserName, mediaId):
		self.__dict = dict()
		self.__dict['ToUserName'] = toUserName
		self.__dict['FromUserName'] = fromUserName
		self.__dict['CreateTime'] = int(time.time())
		self.__dict['MediaId'] = mediaId
	def send(self):
		XmlForm = """
		<xml>
		<ToUserName><![CDATA[{ToUserName}]]></ToUserName>
		<FromUserName><![CDATA[{FromUserName}]]></FromUserName>
		<CreateTime>{CreateTime}</CreateTime>
		<MsgType><![CDATA[image]]></MsgType>
		<Image>
		<MediaId><![CDATA[{MediaId}]]></MediaId>
		</Image>
		</xml>
		"""
		return XmlForm.format(**self.__dict)

class ImageTextMsg(Msg):

    def __init__(self, toUserName, fromUserName,title,description1,picurl,url):
        self.__dict = dict()
        self.__dict['ToUserName'] = toUserName
        self.__dict['FromUserName'] = fromUserName
        self.__dict['CreateTime'] = int(time.time())
        self.__dict['title1'] = title
        self.__dict['description1'] = description1
        self.__dict['picurl'] = picurl
        self.__dict['url'] = url

    def send(self):
        XmlForm =  """     
        <xml>
        <ToUserName><![CDATA[{ToUserName}]]></ToUserName>
        <FromUserName><![CDATA[{FromUserName}]]></FromUserName>
        <CreateTime>{CreateTime}</CreateTime>
        <MsgType><![CDATA[news]]></MsgType>
        <ArticleCount>2</ArticleCount>
        <Articles>
        <item>
        <Title><![CDATA[阿瑟帝国皇家空军\n女擦不可及的巴萨恐\n惧abll反抗军大家发卡死都不放好卡包括减肥的嘎斯科技能否看见撒旦南方科技反抗军的十八分快速多变的反抗军开始的vkb看你]]></Title>
        <Description><![CDATA[]]></Description>
        <PicUrl><![CDATA[{picurl}]]></PicUrl>
        <Url><![CDATA[{url}]]></Url>
        </item>
        <item>
        <Title><![CDATA[{title1}]]></Title>
        <Description><![CDATA[{description1}]]></Description>
        <PicUrl><![CDATA[{picurl}]]></PicUrl>
        <Url><![CDATA[{url}]]></Url>
        </item>         
        </Articles>
        <FuncFlag>1</FuncFlag>
        </xml>
        """
        return XmlForm.format(**self.__dict)
